package cn.ffcs.uec.selfstaff.component;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.IdSpace;
import org.zkoss.zk.ui.event.ForwardEvent;
import org.zkoss.zul.Div;

import cn.ffcs.uec.selfstaff.component.bean.UecSelfPsnjobEditBean;
import cn.ffcs.uec.selfstaff.constant.UecSelfStaffConstants;
import cn.ffcs.uec.staff.manager.UecPsnjobManager;
import cn.ffcs.uec.staff.model.UecPsnjob;
import cn.ffcs.uec.staff.model.UecStaffInfo;
import cn.ffcs.uom.common.util.ApplicationContextUtil;
import cn.ffcs.uom.common.util.IPortletInfoProvider;
import cn.ffcs.uom.common.util.ListboxUtils;
import cn.ffcs.uom.common.util.PubUtil;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.NodeVo;
import lombok.Getter;
import lombok.Setter;
/**
 * @Title:任职信息 CRUD插件
 * @Description:
 * @Copyright: FFCS（C） 2017
 * @Company: FFCS
 * @author Wang Yiren
 * @Version 0.0.1 date:2017年11月27日
 * @since JDK1.6
 */
@Controller
@Scope("prototype")
public class UecSelfPsnjobListboxExt extends Div implements IdSpace {

	private static final long serialVersionUID = -5811398149406451671L;
	/**
	 * 人员基本信息功能 查询出的实体对象
	 */
	private UecStaffInfo uecStaffInfo;
	/**
	 * 对应页面上的bean
	 */
	private UecSelfPsnjobEditBean bean = new UecSelfPsnjobEditBean();
	/**
	 * 人员语言能力实体
	 */
	private UecPsnjob uecPsnjob;
	/**
	 * 人员语言能力查询实体
	 */
	// private UecPsnjob qryUecPsnjob;

	private UecPsnjobManager uecPsnjobManager = (UecPsnjobManager) ApplicationContextUtil
			.getBean("uecPsnjobManager");

	@Getter
	@Setter
	private IPortletInfoProvider portletInfoProvider;

	public UecSelfPsnjobListboxExt() {
		Executions.createComponents(
				UecSelfStaffConstants.UEC_PSNJOB_EXT_LISTBOX_ZUL, this, null);
		Components.wireVariables(this, bean);
		Components.addForwards(this, this, '$');
		this.bindCombobox();
		this.addForward(UecSelfStaffConstants.ON_UEC_PSNJOB_QUERY, this,
				UecSelfStaffConstants.ON_UEC_PSNJOB_QUERY_RESPONSE);


	}

	/**
	 * 初始化
	 */
	public void onCreate() {
	}


	/**
	 * 人员基本信息功能，抛出事件， 事件监听
	 * 
	 * @param event
	 */
	public void onUecPsnjobQueryResponse(ForwardEvent event) {
		uecStaffInfo = (UecStaffInfo) event.getOrigin().getData();
		if (null != uecStaffInfo) {
			uecPsnjob = new UecPsnjob();
			// 集团下发的数据（pk_psndoc 与 staff_id 均不为空）
			if (!StrUtil.isNullOrEmpty(uecStaffInfo.getPkPsndoc())
					&& !StrUtil.isNullOrEmpty(uecStaffInfo.getStaffId())) {
				uecPsnjob.setPkPsndoc(uecStaffInfo.getPkPsndoc());
			} else {
				uecPsnjob.setStaffId(uecStaffInfo.getStaffId());
			}
			this.onQueryUecPsnjobList();
		}
	}


	/**
	 * 查询
	 */
	public void onQueryUecPsnjobList() {
		if (null != uecPsnjob) {
			uecPsnjob = uecPsnjobManager .queryUecPsnjob(uecPsnjob);
			PubUtil.fillBeanFromPo(uecPsnjob, bean);
		}
	}
	/**
	 * 绑定combobox
	 */
	private void bindCombobox() {
		// 是否试用trialFlag
		List<NodeVo> nodeVoList = new ArrayList<NodeVo>();
		String[][] trialFlag = { { "Y", "是" }, { "N", "否" } };
		for (int i = 0; i < trialFlag.length; i++) {
			NodeVo nodeVo = new NodeVo();
			for (int j = 0; j < 1; j++) {
				nodeVo.setId(trialFlag[i][j]);
				nodeVo.setName(trialFlag[i][j + 1]);
			}
			nodeVoList.add(nodeVo);
		}
		ListboxUtils.rendererForEdit(bean.getTrialFlag(), nodeVoList);
		// 人员状态
		ListboxUtils.rendererForEdit(bean.getGlbdef1(), nodeVoList);
		// 是否主职
		ListboxUtils.rendererForEdit(bean.getIsmainjob(), nodeVoList);
		// 是否在岗
		ListboxUtils.rendererForEdit(bean.getPoststat(), nodeVoList);
		//是否结束
		ListboxUtils.rendererForEdit(bean.getEndflag(), nodeVoList);

		// 人员状态jobglbdef1
		List<NodeVo> nodeVoStatusList = new ArrayList<NodeVo>();
		String[][] jobglbdef1 = { { "1001A110000000000681", "在岗" },
				{ "1001A110000000000682", "一般在岗" },
				{ "1001A110000000000683", "交流" },
				{ "1001A110000000000684", "挂职锻炼" },
				{ "1001A110000000000685", "借调" },
				{ "1001A110000000000686", "扶贫" },
				{ "1001A110000000000687", "援藏" },
				{ "1001A110000000000688", "接收交流" },
				{ "1001A110000000000689", "接收挂职" },
				{ "1001A11000000000068A", "接收借调" },
				{ "1001A11000000000068B", "接收援藏（西藏省用）" },
				{ "1001A11000000000068C", "试用见习人员" },
				{ "1001A11000000000068D", "不在岗" },
				{ "1001A11000000000068E", "待岗" },
				{ "1001A11000000000068F", "派往海外" },
				{ "1001A11000000000068G", "派往控股参股公司" },
				{ "1001A11000000000068H", "派往实业公司" },
				{ "1001A11000000000068I", "派往集团外" },
				{ "1001A11000000000068J", "长病假" },
				{ "1001A11000000000068K", "长期学习" },
				{ "1001A11000000000068L", "其他" },
				{ "1001A11000000000068M", "无岗位" } };
		for (int i = 0; i < jobglbdef1.length; i++) {
			NodeVo nodeVo = new NodeVo();
			for (int j = 0; j < 1; j++) {
				nodeVo.setId(jobglbdef1[i][j]);
				nodeVo.setName(jobglbdef1[i][j + 1]);
			}
			nodeVoStatusList.add(nodeVo);
		}
		ListboxUtils.rendererForEdit(bean.getJobglbdef1(), nodeVoStatusList);

		// 人员类型psntype
		List<NodeVo> nodeVoPsntypeList = new ArrayList<NodeVo>();
		String[][] psntype = { { "0", "新进" }, { "1", "变更" }, { "2", "退出" } };
		for (int i = 0; i < psntype.length; i++) {
			NodeVo nodeVo = new NodeVo();
			for (int j = 0; j < 1; j++) {
				nodeVo.setId(psntype[i][j]);
				nodeVo.setName(psntype[i][j + 1]);
			}
			nodeVoPsntypeList.add(nodeVo);
		}
		ListboxUtils.rendererForEdit(bean.getPsntype(), nodeVoPsntypeList);

		// 进入本单位来源jobglbdef10
		List<NodeVo> nodeVoJobglbdef10List = new ArrayList<NodeVo>();
		String[][] jobglbdef10 = { { "1001A1100000000005Z0", "系统外部进入" },
				{ "1001A1100000000005Z1", "应届毕业生" },
				{ "1001A1100000000005Z2", "社会招聘-从派制中招聘" },
				{ "1001A1100000000005Z3", "社会招聘-从外包中招聘" },
				{ "1001A1100000000005Z4", "社会招聘-其他" },
				{ "1001A1100000000005Z5", "政策性接收-复退军人" },
				{ "1001A1100000000005Z6", "政策性接收-转业军人" },
				{ "1001A1100000000005Z7", "政策性接收-其它" },
				{ "1001A1100000000005Z8", "从外单位调入" },
				{ "1001A1100000000005Z9", "成建制划入-联通划转" } };
		for (int i = 0; i < jobglbdef10.length; i++) {
			NodeVo nodeVo = new NodeVo();
			for (int j = 0; j < 1; j++) {
				nodeVo.setId(jobglbdef10[i][j]);
				nodeVo.setName(jobglbdef10[i][j + 1]);
			}
			nodeVoJobglbdef10List.add(nodeVo);
		}
		ListboxUtils.rendererForEdit(bean.getJobglbdef10(),
				nodeVoJobglbdef10List);

		// 岗位工资档次-
		List<NodeVo> nodeVoJobglbdef9List = new ArrayList<NodeVo>();
		String[][] jobglbdef9 = { { "1001A1100000000005KV", "A档" },
				{ "1001A1100000000005KW", "B档" },
				{ "1001A1100000000005KX", "C档" },
				{ "1001A1100000000005KY", "D档" },
				{ "1001A1100000000005KZ", "E档" },
				{ "1001A1100000000005L0", "F档" },
				{ "1001A1100000000005L1", "A档" },
				{ "1001A1100000000005L2", "B档" },
				{ "1001A1100000000005L3", "C档" },
				{ "1001A1100000000005L4", "D档" },
				{ "1001A1100000000005L5", "E档" },
				{ "1001A1100000000005L6", "F档" },
				{ "1001A1100000000005L7", "G档" },
				{ "1001A1100000000005L8", "H档" },
				{ "1001A1100000000005L9", "I档" },
				{ "1001A1100000000005LA", "J档" } };
		for (int i = 0; i < jobglbdef9.length; i++) {
			NodeVo nodeVo = new NodeVo();
			for (int j = 0; j < 1; j++) {
				nodeVo.setId(jobglbdef9[i][j]);
				nodeVo.setName(jobglbdef9[i][j + 1]);
			}
			nodeVoJobglbdef9List.add(nodeVo);
		}
		ListboxUtils
				.rendererForEdit(bean.getJobglbdef9(), nodeVoJobglbdef9List);

		// 试用类型
		// 人员类型trialType
		List<NodeVo> nodeVoTrialTypeList = new ArrayList<NodeVo>();
		String[][] trialType = { { "1", "入职试用" }, { "2", "转岗试用" } };
		for (int i = 0; i < trialType.length; i++) {
			NodeVo nodeVo = new NodeVo();
			for (int j = 0; j < 1; j++) {
				nodeVo.setId(trialType[i][j]);
				nodeVo.setName(trialType[i][j + 1]);
			}
			nodeVoTrialTypeList.add(nodeVo);
		}
		ListboxUtils.rendererForEdit(bean.getTrialType(), nodeVoTrialTypeList);

	}
}
